package com.medicine.common.utils;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author yoko 越军
 * @@Description: TODO 时间工具
 */

public class ScrmDateUtil {
    private final static Logger logger=Logger.getLogger(ScrmDateUtil.class);

    /**
     * 中文x年x月x日
     */
    public static final String CN_yyyyMMdd="yyyy年MM月dd日";
    /**
     * 中文x年x月x日 x时x分x秒
     */
    public static final String HHmm="HH:mm";
    public static final String CN_yyyyMMddHHmmss="yyyy年MM月dd日 HH时mm分ss秒";
    public static final String CN_yyyyMMddHHmm="yyyy年MM月dd日 HH时mm分";
    public static final String CN_MMDD="MM月dd号";
    public static final String HHmmss="HH:mm:ss";
    public static final String yyyyMMddHHmmss="yyyy-MM-dd HH:mm:ss";
    /**
     * 格式 20140206081013 yyyyMMddHHmmss
     */
    public static final String yyyy_MM_dd_HH_mm_ss="yyyyMMddHHmmss";
    /**
     * 格式 201402060810 yyyyMMddHHmm
     */
    public static final String yyyy_MM_dd_HH_mm="yyyyMMddHHmm";
    /**
     * 格式 2014020608 yyyyMMddHH
     */
    public static final String yyyy_MM_dd_HH="yyyyMMddHH";
    /**
     * 格式 20140206 yyyyMMdd
     */
    public static final String yyyy_MM_dd="yyyyMMdd";
    /**
     * 格式 2014/2/6 8:00
     */
    public static final String yyyy_MM_ddHHmm="yyyy/MM/dd HH:mm";

    /**
     * 格式 2014/2/6 8:00:00
     */
    public static final String yyyy_MM_ddHHmmss="yyyy/MM/dd HH:mm:ss";

    /**
     * 格式 2014/2/6
     */
    public static final String yyyy_MM_dd_="yyyy/MM/dd";
    /**
     * yyyyMMdd HH:mm
     */
    public static final String yyyy_MM_dd_HHmm="yyyyMMdd HH:mm";
    public static final String yyyyMMddHHmm="yyyy-MM-dd HH:mm";
    public static final String yyMMddHHmmss="yy-MM-dd HH:mm:ss";
    public static final String yyMMddHHmm="yy-MM-dd HH:mm";
    public static final String YYYY = "YYYY";
    public static final String MMDD = "MM-dd";
    public static final String MMDDsprit = "MM/dd";
    public static final String MMddspritHHmm = "MM/dd HH:mm";
    public static final String yyyyMMddSprit = "yyyy/MM/dd";
    public static final String yyMM="yy-MM";
    public static final String yyyyMM="yyyy-MM";
    public static final String yyMMdd="yy-MM-dd";
    public static final String yyyyMMdd="yyyy-MM-dd";
    public static final String MM="MM";
    public static final String DD = "dd";
    public static final String HH="HH";
    public static final String CN_yyyyMMdd_HHmm = "yyyy年MM月dd日 HH:mm";
    public static final String CN_yyyyMMdd_HHmmss = "yyyy年MM月dd日 HH:mm:ss";

    public static Date parseToDate(String s, String style)throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern(style);
        Date date = null;
        if(s==null||s.length()<8) {
            return null;
        }
        date = simpleDateFormat.parse(s);
        return date;
    }


    public static Date parseToDateMM(String s, String style){
        try{
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
            simpleDateFormat.applyPattern(style);
            Date date = null;
            if(s==null) {
                return null;
            }
            date = simpleDateFormat.parse(s);
            return date;
        }catch (ParseException e) {

        }
        return null;
    }

    public static String parseToString(String s, String style) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern(style);
        Date date = null;
        String str=null;
        if(s==null||s.length()<8) {
            return null;
        }
        date = simpleDateFormat.parse(s);
        str=simpleDateFormat.format(date);

        return str;
    }


    public static String parseToDateString(String s, String style) throws ParseException{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern(style);
        Date date = null;
        String str=null;
        if(s==null||s.length()<8) {
            return null;
        }
        date = simpleDateFormat.parse(s);
        str=simpleDateFormat.format(date);
        return str;
    }

    public static String parseToString(Date date, String style) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        simpleDateFormat.applyPattern(style);
        String str=null;
        if(date==null) {
            return null;
        }
        str=simpleDateFormat.format(date);
        return str;
    }

    public static String getNowTime(){
        Calendar now = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat(yyyyMMddHHmmss);
        String str = formatter.format(now.getTime());
        return str;
    }

    public static String getTimeInMillis(Date startDate, Date endDate){
        long thedaymillis = endDate.getTime()-startDate.getTime();
        return thedaymillis>=1000?thedaymillis/1000+"秒！":thedaymillis+"毫秒！";
    }



    //比较两个时间的大小
    public static int compare_dateString(String time1, String time2)
    {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date d1 = df.parse(time1);
            Date d2 = df.parse(time2);
            if (d1.getTime() > d2.getTime())
            {
                return 1;
            }
            else if (d1.getTime() < d2.getTime())
            {
                return -1;
            }
            else
            {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }

    //比较两个时间的大小
    public static int compare_date(Date d1, Date d2)
    {
        try {
            if (d1.getTime() > d2.getTime())
            {
                return 1;
            }
            else if (d1.getTime() < d2.getTime())
            {
                return -1;
            }
            else
            {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }

    /**
     *
     * @Description: 根据日期Calendar.get dayofweek获取星期几
     * @author jxzhong
     * @version 1.0
     * @date 2014-3-25 下午4:05:01
     * @param day
     * @return
     * @return String
     */
    public static String getWeekCN(int day){
        String week="星期";
        switch(day){
            case 2:week+="一";break;
            case 3:week+="二";break;
            case 4:week+="三";break;
            case 5:week+="四";break;
            case 6:week+="五";break;
            case 7:week+="六";break;
            case 1:week+="日";break;
        }
        return week;
    }

    /**
     *
     * @Description: 根据日期Calendar.get getWeekZJ获取星期几
     * @author jxzhong
     * @version 1.0
     * @date 2014-3-25 下午4:05:01
     * @param day
     * @return
     * @return String
     */
    public static String getWeekZJ(int day){
        String week="周";
        switch(day){
            case 2:week+="一";break;
            case 3:week+="二";break;
            case 4:week+="三";break;
            case 5:week+="四";break;
            case 6:week+="五";break;
            case 7:week+="六";break;
            case 1:week+="日";break;
        }
        return week;
    }

    /**
     * @Description: 获取本周列表
     * @author jxzhong
     * @version 1.0
     * @date 2014-5-14 下午5:58:23
     * @return
     * @return List<Date>
     */
    public static List<Date> getCurrentDayWeekList(Date today){
        List<Date> list=new ArrayList<Date>();
        Calendar cal=Calendar.getInstance();
        if(today!=null){
            cal.setTime(today);
        }
        int day=cal.get(Calendar.DAY_OF_WEEK);//获取当天周did
        try{
            for(int i=day-1;i>0;i--){//前半部日期
                Calendar nextcal=(Calendar) BeanUtils.cloneBean(cal);
                nextcal.add(Calendar.DAY_OF_MONTH, -i);
                list.add(nextcal.getTime());
            }
            for(int i=0;i<=7-day;i++){//后半部日期
                Calendar nextcal=(Calendar)BeanUtils.cloneBean(cal);
                nextcal.add(Calendar.DAY_OF_MONTH, i);
                list.add(nextcal.getTime());
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }

    /**
     *
     * @Description: 显示执行时间
     * @author jxzhong
     * @version 1.0
     * @date 2015-2-7 下午3:03:19
     * @param time
     * @return
     * @return String
     */
    public static String showExecuteTime(Date startTime){
        long millis=new Date().getTime()-startTime.getTime();
        return millis>1000?(millis/1000)+"秒！":millis+"毫秒";
    }

    /**
     *
     * @Description:获取日期前后相差天数
     * @author jxzhong
     * @version 1.0
     * @date 2015-3-4 下午6:26:22
     * @param beginDate
     * @param endDate
     * @return
     * @return long
     */
    public static long getDateMargin(Date beginDate,Date endDate){
        long margin = 0;
        margin = endDate.getTime() - beginDate.getTime();
        margin = margin/(1000*60*60*24);
        return margin;
    }

    public static List<Date> getDateList(Date beginDate,Date endDate){
        int marg = (int) getDateMargin(beginDate, endDate);
        List<Date> list = new ArrayList<Date>();
        for(int i = -marg; i < 0; i++){
            Calendar cal=Calendar.getInstance();
            cal.setTime(endDate);
            cal.add(Calendar.DAY_OF_MONTH, i);
            list.add(cal.getTime());
        }
        return list;
    }
    public static Date getDtime(Date date,int day){
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(cal.DATE, cal.get(cal.DATE)+day);
        return cal.getTime();
    }
    /**
     * 获取当月第一天
     * @return
     */
    public static Date getMonthFirstDay(){
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        return c.getTime();
    }
    /**
     * 获取当月最后一天
     * @return
     */
    public static Date getMonthLastDay(){
        //获取当前月最后一天
        Calendar c= Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }
    // 获取当前时间所在年的周数
    public static int getWeekOfYear(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setMinimalDaysInFirstWeek(7);
        c.setTime(date);

        return c.get(Calendar.WEEK_OF_YEAR);
    }

    // 获取当前时间所在年的最大周数
    public static int getMaxWeekNumOfYear(int year) {
        Calendar c = new GregorianCalendar();
        c.set(year, Calendar.DECEMBER, 31, 23, 59, 59);

        return getWeekOfYear(c.getTime());
    }

    /**
     * @Title: getAge
     * @Description: TODO 根据生日获取年龄
     * @param @param ageDate
     * @param @return    设定文件
     * @return String    返回类型
     * @throws
     */
    public static String getAgeBybirthday(Date ageDate){
        if(ageDate==null){
            return "";
        }
        Calendar birthday = Calendar.getInstance();//2010年10月12日，month从0开始
        birthday.setTime(ageDate);
        Calendar now = Calendar.getInstance();
        int day = now.get(Calendar.DAY_OF_MONTH) - birthday.get(Calendar.DAY_OF_MONTH);
        int month = now.get(Calendar.MONTH) - birthday.get(Calendar.MONTH);
        int year = now.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
        //按照减法原理，先day相减，不够向month借；然后month相减，不够向year借；最后year相减。
        if(day<0){
            month -= 1;
            now.add(Calendar.MONTH, -1);//得到上一个月，用来得到上个月的天数。
            day = day + now.getActualMaximum(Calendar.DAY_OF_MONTH);
        }
        if(month<0){
            month = (month+12)%12;
            year--;
        }
        if(year<=0){
            if(month>0){
                return month+"个月";
            }else{
                return "1个月";
            }
        }else{
            return year+"岁";
        }
    }

    public static Double getAge(Date ageDate){
        if(ageDate==null){
            return 0.0;
        }
        Calendar birthday = Calendar.getInstance();//2010年10月12日，month从0开始
        birthday.setTime(ageDate);
        Calendar now = Calendar.getInstance();
        int day = now.get(Calendar.DAY_OF_MONTH) - birthday.get(Calendar.DAY_OF_MONTH);
        int month = now.get(Calendar.MONTH) - birthday.get(Calendar.MONTH);
        int year = now.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
        //按照减法原理，先day相减，不够向month借；然后month相减，不够向year借；最后year相减。
        if(day<0){
            month -= 1;
            now.add(Calendar.MONTH, -1);//得到上一个月，用来得到上个月的天数。
            day = day + now.getActualMaximum(Calendar.DAY_OF_MONTH);
        }
        if(month<0){
            month = (month+12)%12;
            year--;
        }
        if(year<=0){
            if(month>0){
                if(month>=10) {
                    return Double.parseDouble("0."+month);
                }else {
                    return Double.parseDouble("0.0"+month);
                }
            }else{
                return 0.01;
            }
        }else{
            return new Double(year);
        }
    }
    /**
     * @Description: TODO 生日 和目标日期之前相差的年月日
     * @author 杨文
     * @version 1.0
     * @date 2017年11月7日 上午10:19:52
     * @param birthday
     * @param targetDate
     * @return
     * @return Map<String,Integer>
     */
    public static Map<String,Integer> calculateAge(Date birthday,Date targetDate){
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(targetDate);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(birthday);
        Map<String,Integer> age=new HashMap<String,Integer>();
        int day = cal1.get(Calendar.DAY_OF_MONTH) - cal2.get(Calendar.DAY_OF_MONTH);
        int month = cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
        int year = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
        if (day < 0) {
            month -= 1;
            cal1.add(Calendar.MONTH, -1);
            day = day + cal1.getActualMaximum(Calendar.DAY_OF_MONTH);
        }
        if (month < 0) {
            month = (month + 12) % 12;
            year--;
        }
        age.put("year", year);
        age.put("month", month);
        age.put("day",day);
        return age;
    }

    /**
     * 2个日期相差的月数
     * @param date1 <String>
     * @param date2 <String>
     * @return int
     * @throws ParseException
     */
    public static int getMonthSpace(String date1, String date2)
            throws ParseException {

        SimpleDateFormat sdf  = new SimpleDateFormat("yyyyMMdd");
        Calendar c = Calendar.getInstance();
        c.setTime(sdf.parse(date1));
        int year1 = c.get(Calendar.YEAR);
        int month1 = c.get(Calendar.MONTH);

        c.setTime(sdf.parse(date2));
        int year2 = c.get(Calendar.YEAR);
        int month2 = c.get(Calendar.MONTH);

        int result;
        if(year1 == year2) {
            result = month1 - month2;
        } else {
            result = 12*(year1 - year2) + month1 - month2;
        }
        return Math.abs(result);
    }



    /**
     * @Description: 获取一天的最后时间
     * @author daniel
     * @version 1.0
     * @date 2018-1-27 上午11:49:29
     * @return
     */
    public static String getdaylastTime(){
        Calendar monEight = Calendar.getInstance();
        monEight.set(Calendar.HOUR_OF_DAY, 23);
        monEight.set(Calendar.MINUTE, 59);
        monEight.set(Calendar.SECOND, 59);
        monEight.set(Calendar.MILLISECOND, 0);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String effectiveTime = format.format(monEight.getTime());
        return effectiveTime;
    }

    /**
     * @Description: 计算两个时间段相差多少个月份
     * @author daniel
     * @version 1.0
     * @date 2018-4-13 下午4:00:20
     * @param date1
     * @param date2
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static int calMonths(String date1,String date2,String pattern) throws ParseException{
        SimpleDateFormat sdf=new SimpleDateFormat(pattern);
        Calendar c1=Calendar.getInstance();
        Calendar c2=Calendar.getInstance();
        c1.setTime(sdf.parse(date1));
        c2.setTime(sdf.parse(date2));
        int year =c2.get(Calendar.YEAR)-c1.get(Calendar.YEAR);
        //开始日期若小月结束日期
        if(year<0){
            year=-year;
            return year*12+c1.get(Calendar.MONTH)-c2.get(Calendar.MONTH);
        }
        return year*12+c2.get(Calendar.MONTH)-c1.get(Calendar.MONTH);
    }

    /**
     *  计算预期时间-返回String
     * @param
     * @throws ParseException
     */
    public static String checkTime(int day ,int hour ) throws ParseException{

        SimpleDateFormat sdf=new SimpleDateFormat(yyyyMMddHHmmss);

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, day);
        calendar.add(Calendar.HOUR_OF_DAY, hour);

        String date = sdf.format(calendar.getTime());

        return date;

    }

    /**
     *  计算预期时间-返回Date
     * @param
     * @throws ParseException
     */
    public static Date getDate(Date date, int day ,int hour ) throws ParseException{

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, day);
        calendar.add(Calendar.HOUR_OF_DAY, hour);


        return calendar.getTime();

    }

    /**
     *  计算预期时间-返回预期时间Date 加减分钟
     * @param min
     * @throws ParseException
     */
    public static String getDateByString( String date,int day ,int min ) throws ParseException{
        SimpleDateFormat DF = new SimpleDateFormat(yyyyMMddHHmmss);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DF.parse(date));
        calendar.add(Calendar.DAY_OF_MONTH, day);
        calendar.add(Calendar.MINUTE, min);

        String date2 = DF.format(calendar.getTime());

        return date2;

    }

    /**
     *  计算周几
     * @param
     * @throws ParseException
     */
    public static String getWeekDate( String date ) throws ParseException{
        SimpleDateFormat DF = new SimpleDateFormat(yyyyMMddHHmmss);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DF.parse(date));

        return  getWeekZJ(calendar.get(Calendar.DAY_OF_WEEK));

    }


    /**
     *  计算周几 Int
     * @param
     * @throws ParseException
     */
    public static int  getWeekDateNum( String date ) throws ParseException{
        SimpleDateFormat DF = new SimpleDateFormat(yyyyMMddHHmmss);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DF.parse(date));

        return  calendar.get(Calendar.DAY_OF_WEEK);

    }

    /**
    * @Description: TODO  计算今天周几
    * @author: yuanmenghuai
    * @date: 2020/3/16 11:35
    * @param: []
    * @return int
     **/
    public static int getWeekDateNumStr(String date) throws ParseException{
        SimpleDateFormat DF = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DF.parse(date));

        return  calendar.get(Calendar.DAY_OF_WEEK);
    }

    /**
     *  时间计算
     * @param
     * @throws ParseException
     */
    public static String getCurrentDateStartOrEnd( String date,int type ) throws ParseException{
        SimpleDateFormat DF = new SimpleDateFormat(yyyyMMddHHmmss);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DF.parse(date));
        if(type==1) {
            calendar.set(Calendar.HOUR_OF_DAY,
                    0);
            calendar.set(Calendar.MINUTE,
                    0);
            calendar.set(Calendar.SECOND,
                    0);
        }else {

            calendar.set(Calendar.HOUR_OF_DAY,
                    23);
            calendar.set(Calendar.MINUTE,
                    59);
            calendar.set(Calendar.SECOND,
                    59);

        }


        String date2 = DF.format(calendar.getTime());
        return date2;

    }


    /**
     * 判断输入的日期是否在下周区间
     *
     * @return false：不是下周；true：下周
     * @author nemowang
     */
    public static boolean isNextWeek(Date date) {
        // 设置时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        int dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK) - 1;
        int offset1 = 1 - dayOfWeek;
        int offset2 = 7 - dayOfWeek;
        calendar1.add(Calendar.DATE, offset1 + 7);
        calendar2.add(Calendar.DATE, offset2 + 7);
        // 下周星期一
        String monday = sdf.format(calendar1.getTime());
        System.out.println(monday);
        // 下周星期日
        String sunday = sdf.format(calendar2.getTime());
        System.out.println(sunday);

        String format = sdf.format(date);
        try {
            Date parse = sdf.parse(format);
            Date mon = sdf.parse(monday);
            Date sun = sdf.parse(sunday);
            return parse.compareTo(mon) >= 0 && sun.compareTo(parse) >= 0;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    }



    /**
     *
     * @Description:获取  beginDate+iexpday 和 endDate  的相差天数
     * @author yoko
     */
    public static int getDateDiffer(Date beginDate,Date endDate,Integer iexpday){


        SimpleDateFormat sdf=new SimpleDateFormat(yyyyMMddHHmmss);


        long margin = 0;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(beginDate);
        calendar.add(Calendar.DAY_OF_MONTH, iexpday);
        beginDate = calendar.getTime();

        margin = beginDate.getTime() - endDate.getTime();
//        System.out.println("margin减法"+margin);

        if(margin<0){
            margin=-1;
//            System.out.println("margin<0"+margin);

        }else {
            BigDecimal divide = BigDecimal.valueOf(1000*60*60*24);
            BigDecimal  m = BigDecimal.valueOf(margin).divide(divide,0,BigDecimal.ROUND_HALF_UP);

            margin= m.longValue();
//            System.out.println("margin除法"+margin);

        }
        if(margin==0){
//            System.out.println("margin==0"+margin);
            margin=1;
        }
        System.out.println( sdf.format(calendar.getTime()));
        System.out.println( sdf.format(endDate));
        System.out.println(margin);

        return Long.valueOf(margin).intValue();
    }

    
    /** 
     * @Description: TODO 根据出生日期求 岁数 itype 1=岁 2=月
     * @author: yoko
     * @date: 2020-11-19 11:08
     * @param:  
     */
    public static Integer getAgeOrMonth(Date ageDate,Integer itype){
        if(ageDate==null){
            return 0;
        }
        Calendar birthday = Calendar.getInstance();//2010年10月12日，month从0开始
        birthday.setTime(ageDate);
        Calendar now = Calendar.getInstance();
        int month = now.get(Calendar.MONTH) - birthday.get(Calendar.MONTH);
        int year = now.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
        //按照减法原理，先day相减，不够向month借；然后month相减，不够向year借；最后year相减。
        if(month<0){
            month = (month+12)%12;
            year--;
        }

        System.out.println(month);
        System.out.println(year);
        if(itype==1){return year;
            }else {
            return month;
        }

    }

    /**
     * @Description: TODO 根据年龄出生日期
     * @author: yoko
     * @date: 2020-11-19 11:08
     * @param:
     */
    public static Date getDbrithByAge(Integer iage,Integer imonth){
        if(iage==null && imonth==null){
            return new Date() ;
        }
        if(iage==null ){
           iage=0;
        }
        if(imonth==null){
            imonth=0;
        }


        Calendar birthday = Calendar.getInstance();//2010年10月12日，month从0开始
        birthday.add(Calendar.MONTH,-imonth);
        birthday.add(Calendar.YEAR,-iage);

        return birthday.getTime();

    }
    public static void main(String[] args) throws ParseException {
//        Calendar cal=Calendar.getInstance();
//          Date da=DateUtil.parseToDate("2016-12-6",DateUtil.yyyyMMdd );
//
//        ScrmDateUtil.getAgeOrMonth(da,1);
//
//        System.out.println(ScrmDateUtil.getAgeOrMonth(da,1).toString());
        System.out.println(ScrmDateUtil.getDbrithByAge(21,6));

        // System.out.println( DateUtil.calculateAge(da, new Date()));
//        System.out.println(ScrmDateUtil.getAge(new Date()));
    }




}
